﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fis.Web.Rules.Service
{
    public class NewVersionRule : Agile.Engine.Data.DataRule
    {

        public override void ExecuteNonTrans()
        {
            var action = Paramater["Action"].ToString();
            System.Data.DataTable data = null;
            Status = 1;

            switch (action)
            {
                case "get":
                    data = Info;
                    break;
                case "set":
                    Info = data = Agile.Engine.Utils.ZipUtils.UnZipDataTable(Paramater["data"].ToString());
                    if (Paramater.ContainsKey("version"))
                    {
                        var version = Agile.Engine.Utils.ZipUtils.UnZipBase64(Paramater["version"].ToString());
                        new Fis.Web.Rules.Entry.VersionUpdate().NewVersion = new System.IO.MemoryStream(version);
                    }
                    break;
            }

            if (data != null)
                Result["data"] = Agile.Engine.Utils.ZipUtils.ZipDataTable(data);

        }

        System.Data.DataTable Info
        {
            get
            {
                return Fis.Web.Rules.Entry.VersionUpdate.Config;
            }
            set
            {
                value.Rows[0]["SINDEXDATE"] = DateTime.Now;
                var da = new Agile.Engine.Data.DataAccess() { Context = Model.DataContext, TableName = "TXTRA" };
                da.Update(value.Rows[0]);
            }
        }
    }
}
